<?php

use wbraganca\dynamicform\DynamicFormWidget;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model common\models\SetMeal */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="set-meal-form">

    <?php $form = ActiveForm::begin([
        'options' => ['class' => 'form-horizontal'],
        'id' => 'dynamic-form',
        'fieldConfig' => [
            'options' => ['class' => 'form-group'],
            'template' => "{label}\n<div class=\"col-sm-8\">{input}\n<span class=\"help-block m-b-none\">{error}</span></div><div class='col-sm-8 col-sm-offset-2'>{hint}</div>",
            'labelOptions' => ['class' => 'col-sm-2 control-label'],
        ]
    ]); ?>

    <?= $form->field($model, 'images')->widget(\common\widgets\cos\CosWidget::class, [
        'uploadUrl' => Yii::$app->params['cos']['uploadUrl'],
        'clientOptions' => [
            'max' => 5
        ]
    ])->hint("支持格式：image/jpeg,image/gif,image/png；(最多上传一张)") ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true])?>

    <?= $form->field($model, 'intro')->textarea(['maxlength' => true, 'raw' => 8])?>

    <?= $form->field($model, 'am_stock')->textInput(['maxlength' => true])?>

    <?= $form->field($model, 'pm_stock')->textInput(['maxlength' => true])?>

    <div class="options">
        <div class="form-group field-fgj-area_id_2 required">
            <label class="col-sm-2 control-label" for="fgj-area_id_2">车型规格</label>
            <div class="col-sm-8">
                <?php DynamicFormWidget::begin([
                    'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
                    'widgetBody' => '.container-items', // required: css class selector
                    'widgetItem' => '.item', // required: css class
                    'limit' => 20, // the maximum times, an element can be cloned (default 999)
                    'min' => 1, // 0 or 1 (default 1)
                    'insertButton' => '.add-item', // css class
                    'deleteButton' => '.remove-item', // css class
                    'model' => $modelAttr[0],
                    'formId' => 'dynamic-form',
                    'formFields' => [
                        'type_name',
                        'price'
                    ],
                ]); ?>
                <div class="panel panel-default ">
                    <div class="panel-heading">
                        <h4>
                            <i class="glyphicon glyphicon-envelope"></i>
                            <button type="button" class="add-item btn btn-success btn-sm pull-right"><i
                                        class="glyphicon glyphicon-plus"></i></button>
                        </h4>
                    </div>
                    <div class="panel-body">
                        <div class="container-items"><!-- widgetBody -->
                            <?php foreach ($modelAttr as $i => $item): ?>
                                <div class="item panel panel-default"><!-- widgetItem -->
                                    <div class="panel-heading">
                                        <span class="panel-title-address">规格设置</span>
                                        <h3 class="panel-title pull-left"></h3>
                                        <div class="pull-right">
                                            <button type="button" class="remove-item btn btn-danger btn-xs">
                                                <i class="glyphicon glyphicon-minus"></i></button>
                                        </div>
                                        <div class="clearfix"></div>
                                    </div>
                                    <div class="panel-body">
                                        <?php
                                            if (!$item->isNewRecord) {
                                                echo Html::activeHiddenInput($item, "[{$i}]id");
                                            }
                                        ?>

                                        <?= $form->field($item, "[{$i}]type_name")->textInput(['maxlength' => true]) ?>
                                        <?= $form->field($item, "[{$i}]price")->textInput(['maxlength' => true]) ?>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    </div>
                </div><!-- .panel -->
                <?php DynamicFormWidget::end(); ?>
            </div>
        </div>
    </div>

    <?= $form->field($model, 'content')->widget('kucha\ueditor\UEditor', [
        'clientOptions' => [
            'serverUrl' => \Yii::$app->params['cos']['uploadUeditUrl']
        ]
    ]); ?>

    <div class="form-group">
        <div class="col-sm-4 col-sm-offset-2">
            <?= Html::submitButton($model->isNewRecord ? '保存' : '保存', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        </div>
    </div>

    <?php ActiveForm::end(); ?>

</div>
